home *** CD-ROM | disk | FTP | other *** search
- TITLE 'MSDOS CrcBuild.asm Version 1.2'
-
- ;MSDOS version by Howard Vigorita
- ; NYACC, CP/M SIG
- ; upload comments &/or updates to (718) 539 - 3338
- ;
- ; (derived from CP/M-86 version by Bill Bolton)
- ;
- ;CRCBUILD is a program to build a file in SIG/M
- ;-CATALOG format and print a Cyclic-Redundancy-Check
- ;number based on the CCITT standard polynominal:
- ;
- ; X^16 + X^15 + X^13 + X^7 + X^4 + X^2 + X + 1
- ;
- ;Special Note: this version of CRCBUILD corrects a file read bug common
- ; to a number of MSDOS CRCK implementations and will generate
- ; different CRC values for files not an exact multiple of 128
- ; bytes in size. Do not use this version with a CRCK program
- ; which generates '00 00' CRC values for small files of
- ; less than 128 bytes. This version is compatable with
- ; CRCK version 6.3 or higher which also fixes that bug.
- ;
- ;Original CP/M-80 Version by JOHN L. RAFF WB2MDG/KAPP8107
- ;
- ;VERSION LIST, most recent version first
- ;
- ;11/Nov/85 Added new routine 'bin_2_dec' which supports binary to
- ; ascii-decimal conversions up to 65535 decimal. Also modified
- ; the block-to-K translation routine (in 'finish') to support
- ; file sizes up to 8191K. These new routines are used to
- ; accurately report file sizes up to 999K w/o alteration of
- ; the -CATALOG output format. Line number output routines also
- ; modified to use the new routine but 99 file limit unchanged.
- ; MSDOS, Version 1.2, Howard Vigorita
- ;
- ;26/Oct/85 Supress headers & footers for general purpose use.
- ; MSDOS, Version 1.1a, Howard Vigorita
- ;
- ;25/Oct/85 Corrected bug in disk read routine (peculiar to MSDOS)
- ; whereby the last read block is ignored for files
- ; not an exact multiple of 128 bytes in length. Use with
- ; CRCK version 6.3 or higher for compatability.
- ; MSDOS, Version 1.1, Howard Vigorita
- ;
- ;10/Oct/85 Converted to MSDOS MASM for PC-Blue use. Use only with
- ; pre-existing versions of CRCK which do not process partial
- ; sectors (e.i., small files of less than 128 bytes generate
- ; a CRC of '00 00').
- ; MSDOS, Version 1.0, Howard Vigorita
- ;
- ;30/Oct/84 Added CLOSER routine from CRC-64.A86 for use with
- ; Concurrent PCDOS. Version 1.1 Bill Bolton
- ;
- ;04/Aug/84 CP/M-86 version created from CP/M-80 version. Removed
- ; all in line prints and restructured for 8086 small
- ; memory model. Removed a number of superfluous labels
- ; and some unused data storage. Now uses operating
- ; system 96 byte stack and tested for catalogs
- ; upto 99 entries. If there are more than 100 entries
- ; in a catalog, ID numbers after 99 will display
- ; oddly (the CP/M-80 version does this too).
- ; Version 1.0, Bill Bolton, Software Tools, Australia
- ;
- ; *********** NOTE WELL ************
- ;
- ; This version uses the "old" CRC polynomial code as
- ; described in EDN all those years back and generates
- ; the same CRCKs as most other CRC programs, including
- ; the CRC options in YAM, MODEM and MEX. Note that these
- ; implementations differ from some communications versions
- ; which append two null bytes to the data stream from
- ; which the CRC is derived. Those implementations only do
- ; that so that the receiver can process the data received
- ; together with the transmitted CRC and generate a result
- ; of '00 00'. Such practice, although technically sound,
- ; produces entirely different CRC values than those found in
- ; the CRCKLIST, CRCKFILE and -CATALOG files on most public
- ; domain disks.
-
- ; conditional assembly switches
- ; -----------------------------
- true equ 0FFh
- false equ 0
-
- gen_header equ true ; generate -CATALOG header?
- gen_footer equ true ; generate -CATALOG footer?
- crc_dash equ false ; CRC filenames starting with '-'?
-
- ;
- ;dos EQUATES
- ;
- rdcon equ 1
- wrcon equ 2
- print equ 9
- rcbuf equ 10 ;read console buffer
- cstat equ 11
- open equ 15
- close equ 16
- srchf equ 17
- srchn equ 18
- delete equ 19
- read equ 20
- write equ 21
- make equ 22
- rename equ 23
- stdma equ 26
- dos equ 33 ;MSDOS entry point
- setiv equ 25h ; set interrupt vector
- xctl_c equ 33h ; extend ctl-c checking
- CrtStrm equ 3Ch ; creat file stream
- CloStrm equ 3Eh ; close file stream
- WrtStrm equ 40h ; write to a stream
- TrmProc equ 4Ch ; terminate process
-
- strlmt equ 80 ;string LENGTH LIMIT
-
- tab equ 09H ;ASCII tab
- lf equ 0AH ;ASCII line feed
- cr equ 0DH ;ASCII carriage return
- eof equ 1AH ;end of file marker
-
- sect equ 80h ;Size of dos sector
-
-
- ; Base Page Program Segment Prefix
- ; --------------------------------
- ;
- basepg SEGMENT AT 0
- ; base page fields of interest
- ORG 5Ch
- bfcb db 12 dup(?)
- bfcbext db 4 dup(?)
- bfcb2 db 16 dup(?)
- bfcbrno db (?)
- ;
- ORG 80h
- bdta db 128 dup(?)
- ;
- basepg ENDS
-
-
- ; Program Data Storage Area
- ; -------------------------
- ;
- data SEGMENT PARA MEMORY
-
- tcatz db '-CATALOG.$$$',0
- tcath dw 0
-
- signon db 'CrcBuild, MSDOS Ver 1.2, 12/Nov/85, Howard Vigorita',cr,lf
- db 'CTL-S pauses, CTL-C aborts',cr,lf,cr,lf,'$'
-
- wrong db 'Only decimal digits, please',cr,lf,'$'
-
- enter db 'Enter -CATALOG.xxx number (three digits) - $'
-
- if gen_header
- header db 'PC/Blue Volume '
- header1 db 'NNN',cr,lf
- db 'index name size crc description'
- db cr,lf,'$'
- endif
-
- if gen_footer
- foot1 db cr,lf,cr,lf
- db 'PC/Blue Library -CATALOG Volume Number-'
- DoneExt db 'NNN, $'
-
- foot2 db ' files cataloged',cr,lf
- db ' compiled and distributed by the',cr,lf
- db ' New York Amateur Computer Club, Inc',cr,lf
- db ' Box 106, Church St Station, New York, NY 10008'
- db cr,lf,'$'
- endif
-
- DoneMsg db cr,lf,'done$'
-
- number db cr,lf
- fname1 db 'NNN.','$'
-
- filen db 'xx '
- fname db 'xxxxxxxx.xxx ','$'
-
- fail db ' ++ Open Failed ++','$'
-
- ksize db 'xxxK ','$'
-
- ferror db tab,tab,'++ File Read Error ++',cr,lf,'$'
-
- Nfound db '++ File not Found ++$'
-
- abort db cr,lf,cr,lf,'++ ABORTED ++$'
-
- FullMsg db cr,lf
- db 'Disk Full: CATALOG'
- db '$'
- dtaMSG db cr,lf
- db 'Disk transfer area too small for disk write: CATALOG'
- db '$'
-
- space db cr,lf
- db 'No directory space: CATALOG'
- db '$'
-
- ClsMsg db cr,lf
- db 'Cannot close CATALOG'
- db '$'
-
- fcbnew db 0,'-CATALOGNNN'
- db 0
- db 24 dup(?)
-
- Wflag db 0 ;file write flag
- remain dw 0 ;CRC accumulator
- quanek dw 0 ;count of 128 byte blocks
- mess db 0 ;CRC message character
- MFflg db 1 ;1st time switch
- LineNum db 0 ;quantity of files read
-
- fcbCat db 0,'-CATALOG$$$',0 ;continued in dynamic storage area
-
- dsa equ $ ; start of dynamic storage area
-
-
- fcbcat_cont equ dsa ;db 24 dup(?)
-
- ;fcb components - 37 bytes
- ;
- fcb equ fcbcat_cont+24 ;db 12 dup(?) drive, fname, & ftype
- fcbext equ fcb+12 ;db 4 dup(?) current block & rec size
- fcb2 equ fcbext+4 ;db 16 dup(?) file size, date, & time
- fcbrno equ fcb2+16 ;db 5 dup (?) current rec & rel rec
-
-
- mfreq equ fcbrno+5 ;db 12 dup(?) requested name
- mfcur equ mfreq+12 ;db 12 dup(?) current name
- bufad equ mfcur+12 ;db 2 dup(?) read buffer address
- strcnt equ bufad+2 ;db 2 dup(?) string count storage
- string equ strcnt+2 ;db 11 dup(?) string storage
- str1 equ string+11 ;db 12 dup(?) name storage
- str2 equ str1+12 ;db 8 dup(?) characters after name
- str3 equ str2+8 ;db 5 dup(?) ASCII CRC characters
- str4 equ str3+5 ;db 5 dup(?) buffer
-
- ;
- ;write buffer location
- ;
- catbuf equ str4+5 ; db (?)
-
- dta equ catbuf+1 ; db (?) disk transfer area
-
-
- data ENDS
-
- ;
- ; PROGRAM STARTS HERE
- ; -------------------
- ;
- code SEGMENT para public
- assume CS:code, DS:basepg, SS:a_stack
-
- ; note that data segment register is left pointing at the base page
- ; program segment prefix pending a copy to our own prog data area
- ;
- crcbuild:
-
- mov AX,data ;init extra segment register
- mov ES,AX ; to point to prog data area
- assume ES:data
-
- ; copy base page file control block to our own fbc in prog data area
- ;
- mov SI,offset bfcb ;base pg fcb to source index
- mov DI,offset fcb ;our fcb to dest index
- mov CX,37 ;# of bytes to move
- rep movsb ;block move em
-
- ; copy base page disk transfer buffer to our own dta in prog data area
- ;
- mov SI,offset bdta ;base pg dta to source index
- mov DI,offset dta ;our dta to dest index
- mov CX,64 ;# of words to move
- rep movsw ;block move em
-
- ; point the data segment register at our own data area
- ;
- push ES
- pop DS
- assume DS:data
-
- ; intercept the ctl-C interrupt vector
- ;
- mov AX,setiv*256+23h
- mov DX, offset abext ; point it to our routine
- push DS ; save program data segment
- push CS ; put code segment into
- pop DS ; DS for interrupt handler
- int dos
- pop DS ; restore our data segment
-
- ; turn on extended ctl-c detection
- ;
- mov AX,xctl_c*256+1
- mov DL,1
- int dos
-
- begin:
- xor AL,AL
- mov byte ptr LineNum,AL ;zero the line number counter
- bgn2:
- call CrLf ;turn up a new line
- mov BX,offset signon ;Tell them who we are
- call display
- mov AL,fcb+1 ;get 1st fname char in base page fcb
- cmp AL,' ' ;SEE IF NAME THERE
- jnz begin2 ;YES, CONTINUE
- mov DI,offset fcb+2 ;PUT TOTAL DIRECTORY PATTERN
- mov SI,offset fcb+1 ;IN fcb
- mov byte ptr [SI],'?' ;ALL "?"
- mov CX,10 ;4 CHARACTERS
- rep movsb
- jmp short begin2 ;GO GET UM
-
- ThrNum: ;CHECK FOR THREE ASCII NUMBERS
- call TwoNum
- jz Thr1
- ret ;RETURN IF NOT NUMBERS
-
- Thr1:
- call num
- jnz Thr2
- ret ;RETURN IF A number
-
- Thr2:
- cmp AL,'.' ;CHECK FOR A PERIOD
- jz Thr3
- ret ;RETURN IF NOT A PERIOD
-
- Thr3:
- dec BX ;OTHERWISE BACK UP ONE CHARACTER
- dec CH ;AND ONE COUNT
- cmp AL,AL ;SET ZERO FLAG
- ret
-
- TwoNum:
- call num
- jz num
- ret
-
- num:
- mov AL,byte ptr [BX] ;GET THE CHARACTER
- inc BX ;FOR NEXT CHARACTER
- inc CH ;INCREMENT FOR NEXT COUNT
- cmp AL,'0' ;IS IT LESS THAN 0
- jb NumNot ;BRANCH IF IT IS
- cmp AL,'9'+1 ;IS IT GREATER THAN 9?
- jnb NumNot
- cmp AL,AL ;SET ZERO FLAG
- ret
-
- NumNot:
- cmp AL,'0' ;SHOULD NOT BE EQUAL, RESET ZERO FLAG
- ret
-
- Beg2NG:
- mov BX,offset wrong
- call display
- begin2:
- mov BX,offset enter
- call display
- mov DX, offset str4 ;point to input buffer
- mov byte ptr str4,4 ;write max chars wanted in 1st byte
- mov AH,rcbuf ;read console buffer
- int dos
- call crlf
- cmp byte ptr str4+1,3 ;see if 3 characters returned
- jnz Beg2NG ;try again if not
- mov BX,offset str4+1 ;point to count of characters entered
- xor CH,CH ;zero the counter
- inc BX
- Beg2a:
- call num ;IS IT A DECIMAL number?
- jnz Beg2NG ;BRANCH IF NOT A DECIMAL number
- mov AL,CH ;CHECK QUANTITY OF CHARACTERS
- cmp AL,3
- jnz Beg2a ;BRANCH IF NOT END OF CHARACTERS YET
- mov byte ptr [BX],0 ;ENSURE TERMINATION OF string
- mov SI,offset str4+2 ;COPY number INTO FILE string
- mov DI,offset fname1
- mov CX,3 ;COUNT
- rep movsb
- call CrLf ;turn up a new line
- mov AL,'F' ;INDICATE write FILE open
- mov byte ptr Wflag,AL
-
- ;'DECLARE' fcb FOR OUTPUT FILE
- ;(TEMPORARILY NAMED -CATALOG.$$$)
- ;
- jmp MakeCat
-
- PutCatalog:
- mov byte ptr catbuf,AL
- mov DX, offset catbuf
- mov CX,1
- mov BX, word ptr tcath
- mov AH,WrtStrm ;write 1 char to -catalog file stream
- int dos
- jnc putcat_4
- cmp AX,5
- jz putcat_1
- cmp AX,6
- jz putcat_2
- ret
- PutCat_1:
- mov DX,offset FullMsg
- jmp short putcat_3
- PutCat_2:
- mov DX,offset dtamsg
- PutCat_3:
- mov AH,print
- int dos
- jmp FilErr
- PutCat_4:
- ret
-
- MakeCat:
- mov DX, offset tcatz ;z-string of tmp catalog name
- xor CX,CX ;no file attribute
- mov AH,CrtStrm ;create -catalog file stream
- int dos
- mov word ptr tcath,AX
- jnc makecat_1
- mov AH,print
- mov DX,offset space
- int dos
- jmp FilErr
-
- makecat_1:
- if gen_header
- ;*******
- mov SI,offset fname1 ;plug catalog number into header
- mov DI,offset header1
- mov CX,3
- rep movsb
- mov BX,offset header ;print the header
- call display
- ;*******
- endif
-
- again:
- call MFname ;SEARCH FOR NAMES
- jnae agn_2
- jmp NameTest ;ANOTHER FOUND, print NAME
-
- agn_2:
- mov AL,byte ptr MFflg ;NOTHING FOUND, CHECK
- or AL,AL ; NAME FOUND FLAG
- jz done ;AT LEAST ONE WAS FOUND
- jmp abext ;print msg, then exit
-
- ; close -CATALOG.$$$
- ;
- done: ;close -CATALOG.$$$
- if gen_footer
- ;*******
- mov SI,offset fname1 ;plug catalog number into footer
- mov DI,offset DoneExt
- mov CX,3
- rep movsb
- mov BX,offset foot1 ;print the footer
- call display
-
- mov BL,byte ptr linenum ; binary line number into BX
- xor BH,BH
- mov AL,' ' ; fill character is ascii space
- mov CX,2 ; decimal digit limit
- mov DI,offset foot2 ; pointer to ascii string buffer
- call bin_2_dec ; binary to decimal & plug buffer
-
- mov BX,offset foot2
- call display
-
- ;***
- else
- ;***
-
- call crlf
- ;*******
- endif
-
- done_2:
- mov AL,eof
- call PutCatalog
- mov BX, word ptr tcath
- mov AH,CloStrm ;close -catalog file stream
- int dos
- cmp AX,6
- jnz done_3
- mov AH,print
- mov DX,offset ClsMsg
- int dos
- done_3:
- mov byte ptr Wflag,' ' ;indicate write file closed
- mov SI, offset fname1 ;point to volume # string
- mov DI,offset fcbnew+9 ;file type for rename & delete
- mov CX,3 ;byte count
- rep movsb ;block move
-
- ; ERASE ANY EXISTING OLD FILE
- ;
- erase:
- mov AH,delete
- mov DX,offset fcbnew
- int dos
-
- ; rename -CATALOG.$$$ to -CATALOG.NNN
- ;
- rens:
- mov DI,offset fcbCat+16
- mov SI,offset fcbnew
- mov CX,12
- rep movsb
- mov DX, offset fcbCat
- mov AH,rename
- int dos
-
- ; exit to dos
- ;
- done_5:
- mov BX,offset DoneMsg ;Display end then exit
- call display
- jmp exit
-
- ; test the filename &/or filetype for files to ignore
- ; currently set up to conditionally ignore filenames
- ; beginning with a dash (eg., -CATALOG) but to always
- ; ignore .$$$ filetypes which are usually temporary files
- ;
- NameTest:
- if not crc_dash
- ;*******
- cmp byte ptr fcb+1,'-' ; see if filename starts with a dash
- jnz nametest_0 ; continue if not
- jmp again ; else skip it
-
- nametest_0:
- ;*******
- endif
-
- mov BX,offset fcb+9 ;POINT TO FILETYPE IN fcb
- call TestBad ;CHECK FOR .$$$ FILES
- jnz NameTest_1
- jmp again ;IF ZERO FLAG, IGNORE THEM
-
- NameTest_1:
- mov BX,offset number
- call display
-
- mov AL,'0' ; fill character is ascii zero
- mov BL,byte ptr linenum ; put binary line number into BX
- inc BL ; increment it
- mov byte ptr linenum,BL ; put it back
- xor BH,BH
- mov CX,2 ; decimal digit limit
- mov DI,offset filen ; pointer to ascii string buffer
- call bin_2_dec ; binary to decimal & plug buffer
-
-
- ;MOVE 8 CHARACTERS FROM fcb+1 TO fname
- ;
- mov SI,offset fcb+1
- mov DI,offset fname
- mov CX,8
- rep movsb
-
- ;MOVE 3 CHARACTERS FROM fcb+9 TO fname+9
- ;
- inc DI
- mov CX,3
- rep movsb
-
- ;now print the line number & the filename
- ;
- mov BX,offset filen
- call display
- FNAME2:
- call opn ;open FILE AND BUILD CRC
- jnz fname_3
- jmp again ;BRANCH IF BAD open or read
-
- fname_3:
- jmp abext ;OTHERWISE GET OUT
-
- ;open THE FILE
- ;
- opn:
- mov DX,offset fcb
- mov AH,open
- int dos
- inc AL
- jnz RdInit
- mov BX,offset fail
- call display
- jmp BADRET ;INDICATE BAD open
-
- ;initialize registers used to store variables
- ;
- rdinit:
- xor BX,BX ; init CRC accumulator to 0
- mov word ptr quanek,BX ; init 128 byte block counter
- mov BP,0A097h ; init CCIT CRC polynomial mask word
-
- ; this is the buffer refilling routine
- ;
- filldta:
- mov SI,offset dta ; point to begining of buffer
- mov CX,sect ; logical sector size
- mov DX,offset fcb ; file control block address
- mov AH,read ; read sequential
- int dos
- or AL,AL ; see if full sector returned
- jz filldta_1 ; if so, go to it
- cmp AL,3 ; see if partial sector returned
- jnz finish ; if not, then eof or read error
- filldta_1:
- mov DL,80h ; setup q-bit mask
- inc word ptr quanek ;increment the block counter
-
-
- ; crc routine based on article by Fred Gutman
- ; in 'EDN' magazine June 5, 1979 page 84
- ; optimized for the 8086 by Howard Vigorita
- ;---------------------------------------------
- ;
- crcit:
- test BH,DL ; q-bit mask
- lahf ; save status flags
- shl BX,1 ; double old crc
- lodsb ; AL = byte ptr [SI++]
- add BL,AL ; add in new byte
- sahf ; restore the flags
- jz crcit_1 ; no mask if q-bit was zero
- xor BX,BP ; CRC-16 polynomial mask
- crcit_1:
- loop crcit ; crc next character
- jmp short filldta ; if none left, get some more
-
- finish:
- mov word ptr remain,BX ;save the accumulated CRC remainder
- cmp AL,1 ;physical end of file?
- jnz FilErr ;no, then read error
-
- call closer
- mov BX,word ptr quanek ; count of 128 byte blocks
- add BX,7 ; bump to next 8 block boundary
- shr BX,1 ; turn into 1K block count
- shr BX,1 ; .. by dividing by 2
- shr BX,1 ; .. three times
-
- mov AL,' ' ; fill character is ascii space
- mov CX,3 ; decimal digit limit
- mov DI,offset ksize ; pointer to ascii string buffer
- call bin_2_dec ; binary to decimal & plug buffer
-
- mov BX,offset ksize ; display size in K
- call display
- mov AL,byte ptr remain+1 ;GET MSP OF CRC
- call HEXO ;print IT
- mov AL,' '
- call typer ;TYPE A space
- mov AL,byte ptr remain ;GET LSP OF CRC
- call HEXO ;print IT
- call CLOSER
- GOODRET:
- xor AL,AL
- ret ;RETURN TO CALLER WITH ZERO FLAG SET
-
- FilErr:
- mov BX,offset ferror
- call display ;print THE MESSAGE AND RETURN
- BADRET: ;GENERAL BAD RETURN LOCATION
- xor AL,AL ;SET ZERO FLAG
- inc AL ;RESET ZERO FLAG
- ret ;RETURN TO CALLER
-
- CLOSER:
- mov DX,offset fcb
- mov AH,close
- int dos
- ret
-
- ;HEX OUTPUT
- ;
- HEXO:
- lahf ;SAVE FOR RIGHT DIGIT
- xchg AL,AH
- push AX
- xchg AL,AH
- RCR AL,1 ;RIGHT..
- RCR AL,1 ;..JUSTIFY..
- RCR AL,1 ;..LEFT..
- RCR AL,1 ;..DIGIT..
- call NIBBL ;print LEFT DIGIT
- pop AX ;RESTORE RIGHT
- xchg AL,AH
-
- NIBBL:
- and AL,0FH ;ISOLATE DIGIT
- cmp AL,10 ;IS IS <10?
- jb ISNUM ;YES, NOT ALPHA
- add AL,7 ;add ALPHA BIAS
-
- ISNUM:
- add AL,'0' ;make PRINTABLE
- jmp short typer ;print IT, THEN RETURN
-
- ; console string outputer via AL
- ; expects string pointer in BX, strings terminated with $
- ;
- display:
- mov AL,byte ptr [BX] ;GET CHAR
- cmp AL,'$'
- jz display_2
- display_1:
- call typer ;OUTPUT IT
- inc BX ;POINT TO NEXT
- mov AL,byte ptr [BX] ;TEST
- cmp AL,'$' ;..FOR END
- jnz display_1
- display_2:
- ret ;ret PAST MSG
-
- ; output new line via AL
- ;
- CrLf:
- mov AL,cr ;CARRIAGE RETURN
- call typer
- mov AL,lf ;LINE FEED, FALL INTO 'TYPE'
-
- ; send character in AL to console & output file
- ;
- typer:
- push BX
- and AL,7FH ;STRIP PARITY BIT
- mov DL,AL
- push DX
- call WRFILE ;write TO FILE IF REQUESTED
- pop DX
- mov byte ptr catbuf,DL
- mov DX, offset catbuf
- mov CX,1
- mov AH,WrtStrm ;write 1 char to output stream
- int dos
- pop BX
- ret
-
- ; write character in DL register to output file
- ; if the file switch is set
- ;
- WRFILE:
- mov AL,byte ptr Wflag ;get write file flag
- cmp AL,'F' ;see if it's set
- jz wrf_1 ;go to file write if so
- mov BX,2 ;else, set up error output stream
- ret ;and return
-
- wrf_1:
- mov AL,DL ;get character back
- call PutCatalog
- mov BX,1 ;setup redirection stream
- ret ;and return
-
- ;MULTI-FILE ACCESS SUBROUTINE. ALLOWS PROCESSING
- ;OF MULTIPLE FILES <I.E. *.ASM> FROM DISK. THIS
- ;ROUTINE BUILDS THE PROPER NAME IN THE fcb EACH
- ;TIME IT IS CALLED. CARRY IS SET IF NO MORE NAMES
- ;CAN BE FOUND. THE ROUTINE IS COMMENTED IN PSEUDO
- ;CODE, EACH PSEUDO CODE STATEMENT IS IN <<...>>
- ;
- MFname:
- mov AH,stdma
- mov DX, offset dta
- int dos
- xor AL,AL
- mov byte ptr FCBEXT,AL
- mov byte ptr FCBRNO,AL
-
- ;<<IF FIRST TIME>>
- mov AL,byte ptr MFflg
- or AL,AL
- jz MFN01
-
- ;<<SAVE THE REQUESTED NAME>>
- ;SAVE ORIG REQUEST
- mov SI,offset fcb
- mov DI,offset mfreq
- mov CX,12
- rep movsb
- mov AL,byte ptr fcb
- mov byte ptr mfcur,AL ;SAVE DISK IN CURR fcb
-
- ;<<srchf REQUESTED NAMD>>
- rep movsb
- mov AH,srchf
- mov DX,offset fcb
- int dos
-
- ;<<ELSE>>
- jmp short MFN02
-
- MFN01: ;<<srchf CURRENT NAME>>
- mov SI,offset mfcur
- mov DI,offset fcb
- mov CX,12
- rep movsb
- mov AH,srchf
- mov DX,offset fcb
- int dos
-
- ;<<srchn REQUESTED NAME>>
- mov SI,offset mfreq
- mov DI,offset fcb
- mov CX,12
- rep movsb
- mov AH,srchn
- mov DX,offset fcb
- int dos
-
- ;<<ENDIF>>
- MFN02: ;<<RETURN CARRY IF NOT FOUND>>
- inc AL
- stc
- jnz MFN03
- ret
-
- ;<<MOVE NAME FOUND TO CURRENT NAME>>
- MFN03:
- mov SI, offset dta+1
- push SI ;SAVE NAME POINTER
- mov DI,offset mfcur+1
- mov CX,11
- rep movsb
-
- ;<<MOVE NAME FOUND TO fcb>>
- pop SI
- mov DI,offset fcb+1
- mov CX,11
- rep movsb
-
- ;<<SETUP fcb>>
- xor AL,AL
- mov byte ptr FCBEXT,AL
- mov byte ptr FCBRNO,AL
- mov byte ptr MFflg,AL ;TURN OFF 1ST TIME SW
-
- ;<<RETURN>>
- ret
-
- ;CHECK FOR .$$$ FILES
- ;
- TestBad:
- call TESTIT ;CHECK FIRST ONE FOR '$'
- jz TestBad_1
- ret ;NO, RETURN
-
- TestBad_1:
- call TESTIT ;CHECK SECOND ONE
- jz TESTIT
- ret ;NO, RETURN
-
- ;FALL INTO TESTIT TO CHECK THIRD
- ;
- TESTIT:
- mov AL,byte ptr [BX]
- and AL,7FH ;STRIP ATTRIBUTE
- cmp AL,'$' ;CHECK FOR $ FILETYPE
- lahf
- inc BX
- sahf
- ret
-
-
- ; ABORTED - tell operator and close any inconplete file
- ; to update the FAT, then erase it
- ;
- abext:
- mov AL,byte ptr Wflag ;SEE IF WE ARE MAKING FILE
- cmp AL,'F'
- jnz abext_3 ;NO FILE, SKIP FILE STUFF
- abext_1:
- mov AL,eof
- call PutCatalog
- mov BX, word ptr tcath
- mov AH,CloStrm ;close -catalog file stream
- int dos
- jnc abext_2
- mov AH,print
- mov DX,offset ClsMsg
- int dos
- abext_2:
- mov AH,delete
- mov DX,offset fcbCat
- int dos
-
- abext_3:
- mov DX,offset abort
- mov AH,print
- int dos
-
- ; terminate this program
- ;
- exit:
- mov AH,TrmProc ; terminate process
- int dos
-
-
- ; convert binary word to ascii decimal & write it in buffer
- ; uses the 8086 divide instruction
- ; parameters passed in registres as follows:
- ; AL leading 0 fill character (usually 0 or space)
- ; BX binary word to be converted
- ; CX decimal digit limit (NTE 5)
- ; DX (not preserved)
- ; SI (not preserved)
- ; DI address of buffer to put ascii decimals into
- bin_2_dec:
-
- rep stosb ; block fill, DI += CX
- mov AX,BX ; put binary word into AX
- mov SI,10 ; put divisor in SI
-
- next_digit:
-
- xor DX,DX ; clear dividend high word
- div SI ; AX = (DX:AX)/SI, DX = remainder
- add DX,'0' ; convert DL remainder byte to ascii
- dec DI ; back step in buffer
- mov byte ptr [DI], DL ; put character there
- or AX,AX ; all done? (AX = 0?)
- jnz next_digit ; if not, do another digit
- ret
-
-
- code ENDS ; end of code segment
-
-
-
- ; STACK LOCATION
- ; --------------
- ;
- a_stack SEGMENT PARA STACK
-
- ; use the default disk transfer area & default fcb as a 165 byte stack
-
- a_stack ENDS
-
-
- END crcbuild